package com.xja.book.controller;

import com.xja.book.entity.BookType;
import com.xja.book.service.BookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("bookType")
public class BookTypeController {
    @Autowired
    private BookTypeService bookTypeService;

    @RequestMapping("find")
    public String find(Model model){
        try {
            List<BookType> bookTypeList = bookTypeService.selectAll();
            model.addAttribute("bookTypeList",bookTypeList);
            return "type_list";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @RequestMapping("add")
    public String addBookType(BookType bookType){
        try {

            bookTypeService.addBoookType(bookType);
            return "redirect:/bookType/find.do";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
